<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Field_findings_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}

public function get_status($num,$name,$from){
	 	$sql = "";
        $sql1 = ""; 
        $sql2 = "";
        $sql3 = "";
        $arr = array();
        if(!empty($num)){
          $sql1 = " aea.zone_1 = '". $num ."' ";
          array_push($arr,$sql1);
        }
        if(!empty($name)){
          $sql2 = " umr.bill_year = '". $name."' ";
          array_push($arr,$sql2);
        }

        if(!empty($from)){
          $sql3 = " umr.bill_month = '". $from."'";
          array_push($arr,$sql2);
        }

        $where = "WHERE ".implode(' AND ',$arr);

        $sql = "SELECT aa.`acct_name`, aea.`zone_1`, umr.field_findings FROM ubs_meter_readings umr
  JOIN ar_account aa ON aa.`account_id` = umr.`account_id`
  JOIN ar_entity_address aea ON aa.`acct_addr` = aea.`entity_id` ".$where." AND umr.field_findings <> '' AND umr.field_findings IS NOT NULL";

        $q = $this->db->query($sql);
        return $q->result();
}

public function getzoning($zone) {
    $this->db->where('zone_code', $zone);
    $query = $this->db->get('ar_zones');
    return $query->result();
  }

public function getzoning2($zone) {
    $this->db->where('zone_code', $zone);
    $query = $this->db->get('ar_zone_values');
    return $query->result();
  }

}